package com.fd.extends5override;

public class Test2 {
    public static void main(String[] args) {
        // 目标：方法重新的常见应用场景：子类重写Obiect的toString方法，以便返回对象的内容。
        Student s = new Student("小王", 18, '男');
        System.out.println(s.toString());
        System.out.println(s);
        //
    }
}

class Student {
   private String name;
   private int age;
   private char sex;

    @Override
    public String toString() {
        return "Student{" +
                "name='" + name + '\'' +
                ", age=" + age +
                ", sex=" + sex +
                '}';
    }

    public Student() {
   }

    public Student(String name, int age, char sex) {
        this.name = name;
        this.age = age;
        this.sex = sex;
    }

    public String getName() {
        return name;
    }

    public void setName(String name) {
        this.name = name;
    }

    public int getAge() {
        return age;
    }

    public void setAge(int age) {
        this.age = age;
    }

    public char getSex() {
        return sex;
    }

    public void setSex(char sex) {
        this.sex = sex;
    }
}
